package puzzle.akari.loader;

import puzzle.akari.data.AkariBoard;
import puzzle.akari.data.BlockNumber;
import puzzle.common.loader.AbstractLoader;
import puzzle.common.loader.Preprocessor;

public class AkariLoader extends AbstractLoader<AkariBoard> {

	@Override
	protected AkariBoard process(Preprocessor pp) {
		AkariBoard b = new AkariBoard(pp.getWidth(), pp.getHeight());
		for (int y = 0; y < b.height; y++) {
			String[] fields = pp.getLines().get(y);
			for (int x = 0; x < fields.length; x++) {
				int c = fields[x].charAt(0);
				switch (c) {
				case 'X':
					b.setBlockNumber(x, y, BlockNumber.UNNUMBERED_BLOCK);
					break;
				case '0':
				case '1':
				case '2':
				case '3':
				case '4':
					b.setBlockNumber(x, y, c - '0');
					break;
				default:
					b.setBlockNumber(x, y, BlockNumber.NON_BLOCK);
					break;
				}
			}
		}
		return b;
	}

}
